package com.settlement.system.controller;

import com.settlement.system.csv.CsvExportBuilder;
import com.settlement.system.csv.CsvExportUtil;
import com.settlement.system.common.enums.ExcelFileType;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblWxsphBillDetail;
import com.settlement.system.service.IBaseService;
import com.settlement.system.service.ITblWxsphBillDetailService;
import com.settlement.system.service.csv.DateSpiltCsvDatas;
import com.settlement.system.common.util.common.FasUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.Map;

/**
 * RR-微信视频号账单 前端控制器
 * @author xiaochuan
 * @since 2023-12-26
 */

@Api(tags = "RR-微信视频号账单",description = "RR-微信视频号账单")
@RestController
@RequestMapping("/tbl_wxsph_bill_detail")
public class TblWxsphBillDetailController extends ExcelController<TblWxsphBillDetail> {


    @Value("${system.export-root.path}")
    private String exportRootPath;
    
    @Resource
    private ITblWxsphBillDetailService tblWxsphBillDetailService;

    @Override
    public IBaseService init() {
        return tblWxsphBillDetailService;
    }

    @Override
    public Class<?> getModelClass() {
        return TblWxsphBillDetail.class;
    }

    @Override
    protected void setParamsModel(Map<String, Object> model) {
        FasUtil.formatInQueryCondition(model,"shopNo");
        super.setParamsModel(model);
    }

    @Override
    protected void setFootModel(Map<String, Object> result, Map<String, Object> model) throws ServiceException {
        result.put("foot",tblWxsphBillDetailService.getFoot(model));
    }

    @Override
    public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String, Object> params = buildParam(request);
        setParamsModel(params);
        Object fileName = "RR-微信视频号账单";
        String path = exportRootPath + System.currentTimeMillis() + File.separator;
        CsvExportUtil.createCsv()
                .headClass(TblWxsphBillDetail.class)
                .fileName(fileName.toString())
                .fileType(ExcelFileType.XLSX)
                .model(CsvExportBuilder.MULTI_ZIP_MODEL)
                .parentPath(path)
                .csvDatas(new DateSpiltCsvDatas(tblWxsphBillDetailService, params))
                .export(request, response);
    }
}

